package fonkin.com.wifisignapp.acticity.news;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.webkit.WebSettings;
import android.webkit.WebView;

import java.io.Serializable;

import fonkin.com.wifisignapp.R;
import fonkin.com.wifisignapp.bean.news.NewsInfor;
import fonkin.com.wifisignapp.retrofit.BaseRetrofit;
import fonkin.com.wifisignapp.utils.ReturnVo;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class NewsDetail extends AppCompatActivity {


    NewsInfor newsInfor = null;
    WebView webview;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_news_detail);
        newsInfor =(NewsInfor) this.getIntent().getSerializableExtra("newsInfor");


        webview = (WebView) findViewById(R.id.news_detail);
        WebSettings webSettings = webview.getSettings();
        //设置WebView属性，能够执行Javascript脚本
        webSettings.setJavaScriptEnabled(true);
        //设置可以访问文件
        webSettings.setAllowFileAccess(true);
        //设置支持缩放
        webSettings.setBuiltInZoomControls(false);
        webSettings.setLoadsImagesAutomatically(true); //支持自动加载图片
        webSettings.setDefaultTextEncodingName("utf-8");//设置编码格式
        //
        if (!newsInfor.getId().equals("")){
            BaseRetrofit.GetBaseRetrofit().getNewsDetail(newsInfor.getId()).enqueue(new Callback<ReturnVo<NewsInfor>>() {
                @Override
                public void onResponse(Call<ReturnVo<NewsInfor>> call, Response<ReturnVo<NewsInfor>> response) {
                    if (response.isSuccessful()&&response.body().getCode().equals(1)){
                        NewsInfor data = response.body().getData();
                        webview.loadData("<h1 style='text-align: center;margin-top:10px'>"+data.getTitle()+"</h1>"+
                                        "<h5 style='text-align: center;color:#bfbfbf'>发布单位：["+data.getDeptName()+"]</h5>"+
                                        "<h5 style='text-align: center;color:#bfbfbf'>发布时间:["+data.getPublishTime()+"]&nbsp;&nbsp;&nbsp;浏览数："+data.getBrowseNum()+"</h5>"+
                                       data.getDetail(),
                                       "text/html","UTF-8"
                        );
                    }
                }

                @Override
                public void onFailure(Call<ReturnVo<NewsInfor>> call, Throwable t) {

                }
            });
        }


    }
}
